#include <iostream>
#include <queue>
#include <string.h>
using namespace std;

int n = 0;
int Nodes[100][100] = {0};
int vis[100][100] = {0};

struct address
{
    int x = 0;
    int y = 0;
};

void bfs()
{   
    address root;
    queue<address> q;

    q.push(root);

    while(!q.empty())
    {
        address now = q.front();
        q.pop(); 
        vis[now.x][now.y] = 1;

        int x, y;       
        x = now.x, y = now.y + 1;
        if(x >= 0 && x<= n+1 && y >= 0 
            && y <= n+1 && vis[x][y] == 0)
        {
            address temp;
            temp.x = x;
            temp.y = y;
            q.push(temp);
        }

        x = now.x, y = now.y - 1;
        if(x >= 0 && x<= n+1 && y >= 0 
            && y <= n+1 && vis[x][y] == 0)
        {
            address temp;
            temp.x = x;
            temp.y = y;
            q.push(temp);
        }

        x = now.x - 1, y = now.y;
        if(x >= 0 && x<= n+1 && y >= 0 
            && y <= n+1 && vis[x][y] == 0)
        {
            address temp;
            temp.x = x;
            temp.y = y;
            q.push(temp);
        }

        x = now.x + 1, y = now.y;
        if(x >= 0 && x<= n+1 && y >= 0 
            && y <= n+1 && vis[x][y] == 0)
        {
            address temp;
            temp.x = x;
            temp.y = y;
            q.push(temp);
        }
    }

    
}
int main()
{
    cin >> n;

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            cin >> Nodes[i][j];
            if(Nodes[i][j] == 1)
                vis[i][j] = 1;
        }
    }

    bfs();

    for(int i = 1; i <= n ; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            if(vis[i][j] == 0)
                cout << "2 ";
            else
                cout << Nodes[i][j]<< " ";
        }
        cout << endl;
    }

}